package com.qifenqian.turbot.module.presenter

import android.content.Context
import com.qifenqian.turbot.base.BasePresenter
import com.qifenqian.turbot.module.contract.RestaurantContract
import com.qifenqian.turbot.module.entity.request.PhotoRequest
import com.qifenqian.turbot.module.entity.response.UploadEntity
import com.qifenqian.turbot.module.entity.response.restaurant.CuisineEntity
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantEntity
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantPhotoEntity
import com.qifenqian.turbot.module.entity.response.restaurant.RestaurantTableEntity
import com.qifenqian.turbot.module.model.RestaurantModel
import com.qifenqian.turbot.net.ModelCallback

/**
 * @author H
 * @createTime 2018/12/25 16:05
 * @description
 * @see
 * @since
 */
class RestaurantPresenter(context: Context, view: RestaurantContract.View) : BasePresenter<RestaurantContract.View, RestaurantModel>(context, view), RestaurantContract.Presenter {

    override fun deleteTableInfo(id: Int, position: Int) {
        mModel.deleteTableInfo(id, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.deleteTableInfoResult(true, msg = msg!!, position = position)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.deleteTableInfoResult(false, code, msg!!)
            }
        })
    }

    override fun uploadFile(filePaths: MutableList<String>) {
        mModel.uploadFile(filePaths, object : ModelCallback<UploadEntity> {
            override fun onSuccess(msg: String?, t: UploadEntity?) {
                mView?.uploadFileResult(true, msg = msg, uploadEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.uploadFileResult(false, msg = msg)
            }
        })
    }

    override fun savePhotoList(request: PhotoRequest) {
        mModel.savePhotoList(request, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.savePhotoListResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.savePhotoListResult(false, code, msg)
            }
        })
    }
//    override fun savePhotoList(ids: MutableList<Int>, restaurantPhotoPaths: MutableList<String>) {
//        mModel.savePhotoList(ids, restaurantPhotoPaths, object : ModelCallback<Nothing> {
//            override fun onSuccess(msg: String?, t: Nothing?) {
//                mView?.savePhotoListResult(true, msg = msg)
//            }
//
//            override fun onFailure(code: Int, msg: String?) {
//                mView?.savePhotoListResult(false, code, msg)
//            }
//        })
//    }

    override fun getPhotoList() {
        mModel.getPhotoList(object : ModelCallback<List<RestaurantPhotoEntity>> {
            override fun onSuccess(msg: String?, t: List<RestaurantPhotoEntity>?) {
                mView?.getPhotoListResult(true, restaurantPhotoEntities = t!!)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getPhotoListResult(false, code, msg)
            }
        })
    }

//    override fun saveTableInfo(restaurantId: String) {
//        mModel.saveTableInfo(object : ModelCallback<Nothing> {
//            override fun onSuccess(msg: String?, t: Nothing?) {
//                mView?.saveTableInfoResult(true, msg = msg!!)
//            }
//
//            override fun onFailure(code: Int, msg: String?) {
//                mView?.saveTableInfoResult(false, code, msg!!)
//            }
//        })
//    }

    override fun saveTableInfo(saveTableRequest: RestaurantTableEntity) {
        mModel.saveTableInfo(saveTableRequest, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.saveTableInfoResult(true, msg = msg!!)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.saveTableInfoResult(false, code, msg!!)
            }
        })
    }

    override fun getTableInfo() {
        mModel.getTableInfo(object : ModelCallback<RestaurantTableEntity> {
            override fun onSuccess(msg: String?, t: RestaurantTableEntity?) {
                mView?.getTableInfoResult(true, restaurantTableEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getTableInfoResult(false, code, msg)
            }
        })
    }

    override fun changeRestaurantIntroduction(introduction: String) {
        mModel.changeRestaurantIntroduction(introduction, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.changeRestaurantIntroductionResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.changeRestaurantIntroductionResult(false, code, msg)
            }
        })
    }

    override fun changePersonConsume(consumePerPerson: Int) {
        mModel.changePersonConsume(consumePerPerson, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.changePersonConsumeResult(true, msg = msg, personConsume = consumePerPerson)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.changePersonConsumeResult(false, code, msg)
            }
        })
    }

    override fun changeAddress(province: String, city: String, area: String, address: String) {
        mModel.changeAddress(province, city, area, address, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.changeAddressResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.changeAddressResult(false, code, msg)
            }
        })
    }

    override fun changeBusinessTime(openTime: String, closeTime: String) {
        mModel.changeBusinessTime(openTime, closeTime, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.changeBusinessTimeResult(true, msg = msg)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.changeBusinessTimeResult(false, code, msg)
            }
        })
    }

    override fun setAvailableChooseSeat(onlineReservation: Int, isChecked: Boolean) {
        mModel.setAvailableChooseSeat(onlineReservation, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.setAvailableChooseSeatResult(true, msg, isChecked)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.setAvailableChooseSeatResult(false, msg)
            }
        })
    }

    override fun changeRestaurantPhone(restaurantPhone: String) {
        mModel.changeRestaurantPhone(restaurantPhone, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.changeRestaurantPhoneResult(true, msg = msg, phone = restaurantPhone)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.changeRestaurantPhoneResult(false, code, msg)
            }
        })
    }

    override fun chooseCuisine(cuisine: String) {
        mModel.chooseCuisine(cuisine, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.chooseCuisineResult(true)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.chooseCuisineResult(false, code, msg)
            }
        })
    }

    override fun getCuisineList() {
        mModel.getCuisineList(object : ModelCallback<List<CuisineEntity>> {
            override fun onSuccess(msg: String?, t: List<CuisineEntity>?) {
                mView?.getCuisineListResult(true, cuisineEntities = t!!)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getCuisineListResult(false, code, msg)
            }
        })
    }

    override fun getRestaurantInfo(showDialog: Boolean) {
        mModel.getRestaurantInfo(showDialog, object : ModelCallback<RestaurantEntity> {
            override fun onSuccess(msg: String?, t: RestaurantEntity?) {
                mView?.getRestaurantInfoResult(true, msg = msg, restaurantEntity = t)
            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.getRestaurantInfoResult(false, msg = msg)
            }
        })
    }

    override fun editShortName(shortName: String) {
        mModel.editShortName(shortName, object : ModelCallback<Nothing> {
            override fun onSuccess(msg: String?, t: Nothing?) {
                mView?.editShortNameResult(true, msg = msg, shortName = shortName)

            }

            override fun onFailure(code: Int, msg: String?) {
                mView?.editShortNameResult(false, code, msg)
            }
        })

    }

    override fun createModel(): RestaurantModel {
        return RestaurantModel(mContext)
    }
}
